package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"time"
	"video/models"
)

type VideoController struct {
	beego.Controller
}
type JsonMsg struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (c *VideoController) Add() {
	title := c.GetString("title")
	intro := c.GetString("intro")
	img := c.GetString("img")
	times := time.Now()
	user := c.GetString("user")
	video := models.Video{
		Title: title,
		Intro: intro,
		Img:   img,
		Times: times,
		User:  user,
	}
	err := models.DB.Create(&video).Error
	if err != nil {
		c.Data["json"] = JsonMsg{
			Code: 500,
			Msg:  "添加失败",
			Data: nil,
		}
		c.ServeJSON()
	} else {
		c.Data["json"] = JsonMsg{
			Code: 200,
			Msg:  "添加成功",
			Data: nil,
		}
		c.ServeJSON()
	}
}
